package com.dex4d.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.dex4d.R;
import com.framework.util.StringUtil;


/**
 * Created by chengyuchun on 2018/10/22.
 *
 */
public class CommonMessageDialog extends CustomDialog {

    public enum DialogStyle {
        TIP,    // 提示
        NOTICE; // 通知
    }

    private DialogStyle dialogStyle;

    private TextView tvTitle, tvMsg;

    private View vDivide;

    private String strTitle, strMsg, strLeftBtn, strRightBtn;

    private Object tag = null;

    public CommonMessageDialog(Context context) {
        this(context, DialogStyle.NOTICE);
    }

    public CommonMessageDialog(Context context, DialogStyle style) {
        super(context, R.layout.dialog_common_msg);

        dialogStyle = style;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvMsg = (TextView) findViewById(R.id.tv_msg);
        vDivide = (View) findViewById(R.id.v_divide);
        switch (dialogStyle) {
            case NOTICE:
                btnLeft.setVisibility(View.VISIBLE);
                btnRight.setVisibility(View.VISIBLE);

                btnLeft.setText(R.string.cancel);
                btnRight.setText(R.string.confirm);
                break;

            case TIP:
                btnLeft.setVisibility(View.VISIBLE);
                btnRight.setVisibility(View.GONE);
                vDivide.setVisibility(View.GONE);
                btnLeft.setText(R.string.confirm);
                break;
        }
    }

    public void setTitle(String title) {

        this.strTitle = title;
    }


    public void setMsg(String msg) {
        this.strMsg = msg;
    }

    public void setLeftBtnTxt(String txt) {
        this.strLeftBtn = txt;
    }

    public void setRightBtnTxt(String txt) {
        this.strRightBtn = txt;
    }

    @Override
    public void show() {
        super.show();
        if(StringUtil.isEmpty(strTitle)){
            tvTitle.setVisibility(View.GONE);
        }else {
            tvTitle.setVisibility(View.VISIBLE);
            tvTitle.setText(strTitle);
        }
        tvMsg.setText(strMsg);

        if (strLeftBtn != null) {
            btnLeft.setText(strLeftBtn);
        }

        if (strRightBtn != null) {
            btnRight.setText(strRightBtn);
        }

    }

    public Object getTag() {
        return tag;
    }

    public void setTag(Object tag) {
        this.tag = tag;
    }
}
